package com.ruoyi.common.utils.poi;

import com.ruoyi.common.core.domain.AjaxResult;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

public class UploadExcelUitl {

    public static AjaxResult processFile(MultipartFile file) throws IOException, InvalidFormatException {
        String fileName = file.getOriginalFilename();
        if(fileName.length()<6|| !fileName.substring(fileName.length()-4).equals(".xls")){
            return AjaxResult.error("文件错误，请使用xls格式的表格模版文件。");
        }
        Workbook wb = WorkbookFactory.create(file.getInputStream());
        Sheet sheet = wb.getSheetAt(0);
        if (sheet == null){
            return AjaxResult.error("文件sheet不存在");
        }
        int rows = sheet.getPhysicalNumberOfRows();
        int rowCount = 3;
        return AjaxResult.success("操作成功");
    }
}
